﻿<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="true" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=1600, initial-scale=1.0">
    <link rel="stylesheet" href="icofont/css/all.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/manager.css">
    <link rel="stylesheet" href="css/user.css">
    <link rel="shortcut icon" href="images/favicon.ico">
    <title>用户管理</title>
</head>

<body>
    <div class="nav">
        <a href="#"><img src="images/logo.png" width="130" height="48"></a>
        <ul>
            <li>
                <div class="usr">
                    <span class="fas font">&#xf21b;</span>管理员
                    <div class="choice">
                        <span class="fas font"><a href="/query/user">&#xf064;返回首页</a></span>
                        <p class="line"></p>
                        <span class="fas font"><a href="/query/logout">&#xf14d;退出登录</a></span>
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div>
        <div class="menu">
            <span><a href="/query/user">返回首页</a></span>
            <span class="fas font"><a href="#">&#xf2b9;&nbsp;&nbsp;用户管理</a></span>
            <span class="fas font"><a href="/query/manager/querys">&#xf328;&nbsp;&nbsp;问卷管理</a></span>
            <span class="fas font"><a href="/query/logout">&#xf14d;&nbsp;&nbsp;退出登录</a></span>
        </div>
        <div class="content">
            <div class="table">
                <div class="table-title">
                    <span class="fas font">&#xf2c2;&nbsp;&nbsp;用户列表</span>
                </div>
                <table>
                    <tr>
                        <th>用户名</th>
                        <th>注册时间</th>
                        <th>权限</th>
                        <th>操作</th>
                    </tr>
                    <c:forEach items="${users}" var="user">
                        <tr>
                            <td>${user.userName}</td>
                            <td>${user.createTime}</td>
                            <c:choose>
                                <c:when test="${user.manager eq true }">
                                    <td>
                                        <span class="manager">管理员</span>
                                    </td>
                                    <td>
                                        <c:if test="${user.userName != manager }">
                                            <a class="cancel-manager" href="/query/manager/update/${user.userName}/0">
                                                <span>取消管理员</span>
                                            </a>
                                            <a class="delete-user" href="/query/manager/deleteUaser/${user.userName}">
                                                <span>删除</span>
                                            </a>
                                        </c:if>
                                    </td>
                                </c:when>
                                <c:otherwise>
                                    <td>
                                        <span class="user">普通用户</span>
                                    </td>
                                    <td>
                                        <c:if test="${user.userName != manager }">
                                            <a class="set-manager" href="/query/manager/update/${user.userName}/1">
                                                <span>设为管理员</span>
                                            </a>
                                            <a class="delete-user" href="/query/manager/deleteUaser/${user.userName}">
                                                <span>删除</span>
                                            </a>
                                        </c:if>
                                    </td>
                                </c:otherwise>
                            </c:choose>
                        </tr>
                    </c:forEach>
                </table>
                <form class="goto-page" action="#" method="post">
                    <input type="button" name="prev" value="<" class="btn" onclick="gotoPage(1)">
                    <li>第</li>
                    <input type="text" id="page" value="${userPage}" size="1" name="page">
                    <li>页</li>
                    <input type="button" name="next" value=">" class="btn" onclick="gotoPage(2)">
                    <input type="button" value="跳转" class="btn btn-primary" onclick="gotoPage(3)">
                </form>
            </div>
        </div>
    </div>
</body>
<script src="js/jquery-3.6.0.min.js"></script>
<script>
    var page = $("#page").val();
    function gotoPage(choice) {
        var temp = page;
        if (choice == 1) {
            temp--;
        } else if (choice == 2) {
            temp++;
        } else {
            temp = $("#page").val();
        }
        if (temp <= 0) {
            alert("页码不能小于等于0!");
        } else {
            $.ajax({
                url: "/query/manager/gotoPage",
                type: "POST",
                data: {
                    "page": temp
                },
                traditional: true,
                success: function (result) {
                    if (result == "true") {
                        location.reload();
                    } else {
                        alert("该页不存在!");
                    }
                }
            });
        }
    }
</script>

</html>